home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11.lha / libX11 / regions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  6.2 KB  |  260 lines

  1. /* Copyright (c) 1996 by Terje Pedersen.  All Rights Reserved   */
  2. /*                                                              */
  3. /* By using this code you will agree to these terms:            */
  4. /*                                                              */
  5. /* 1. You may not use this code for profit in any way or form   */
  6. /*    unless an agreement with the author has been reached.     */
  7. /*                                                              */
  8. /* 2. The author is not responsible for any damages caused by   */
  9. /*    the use of this code.                                     */
  10. /*                                                              */
  11. /* 3. All modifications are to be released to the public.       */
  12. /*                                                              */
  13. /* Thats it! Have fun!                                          */
  14. /* TP                                                           */
  15. /*                                                              */
  16.  
  17. /***
  18.    NAME
  19.      regions
  20.    PURPOSE
  21.      
  22.    NOTES
  23.      
  24.    HISTORY
  25.      Terje Pedersen - Aug 24, 1995: Created.
  26. ***/
  27.  
  28. #include <intuition/intuition.h>
  29. #include <intuition/intuitionbase.h>
  30.  
  31. #include <graphics/gfx.h>
  32. #include <graphics/gfxbase.h>
  33. #include <graphics/gfxmacros.h>
  34. #include <graphics/displayinfo.h>
  35. #include <devices/timer.h>
  36.  
  37. #include <proto/intuition.h>
  38. #include <proto/graphics.h>
  39. #include <proto/gadtools.h>
  40. #include <proto/layers.h>
  41.  
  42. #include <dos.h>
  43. #include <signal.h>
  44. #include <stdlib.h>
  45. #include <time.h>
  46. #include <stdio.h>
  47. #include <math.h>
  48.  
  49. #include "libX11.h"
  50.  
  51. #include <X11/X.h>
  52. #include <X11/Xlib.h>
  53. #include <X11/Xutil.h>
  54.  
  55. #include "amigax_proto.h"
  56. #include "amiga_x.h"
  57.  
  58. #define DOCLIPPING
  59. #define DOREGIONS
  60.  
  61. Region XPolygonRegion(points, n, fill_rule)
  62.      XPoint points[];
  63.      int n;
  64.      int fill_rule;
  65. {
  66. #ifdef DOREGIONS
  67.   int i;
  68.   struct Rectangle rec;
  69.   int nXMin,nXMax,nYMin,nYMax;
  70.   struct Region *reg;
  71.   
  72.   nXMin=points[0].x;
  73.   nYMin=points[0].y;
  74.   nXMax=points[0].x;
  75.   nYMax=points[0].y;
  76.   for(i=1;i<n;i++){
  77.     if(points[i].x<nXMin) nXMin=points[i].x;
  78.     if(points[i].y<nYMin) nYMin=points[i].y;
  79.     if(points[i].x>nXMax) nXMax=points[i].x;
  80.     if(points[i].y>nYMax) nYMax=points[i].y;
  81.   }
  82.   reg=(struct Region*)XCreateRegion();
  83.  
  84.   rec.MinX=nXMin;
  85.   rec.MinY=nYMin;
  86.   rec.MaxX=nXMax;
  87.   rec.MaxY=nYMax;
  88. /*
  89. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  90.   printf("WARNING: XPolygonRegion [%d,%d][%d,%d]\n",rec.MinX,rec.MinY,rec.MaxX,rec.MaxY);
  91. #endif
  92. */
  93.   XUnionRectWithRegion(&rec,(Region)reg,(Region)reg);
  94.   return (Region)reg;
  95. #else
  96.   return 0;
  97. #endif /* DOREGIONS */
  98. }
  99.  
  100. Region XCreateRegion(void){
  101. #ifdef DOREGIONS
  102.   return (Region)NewRegion();
  103. #else
  104.   return 0;
  105. #endif /* DOREGIONS */
  106. }
  107.  
  108. XSubtractRegion(sra, srb, dr_return)
  109.      Region sra, srb;
  110.      Region dr_return;
  111. {
  112. #if (DEBUGXEMUL_ENTRY)
  113.   printf("XSubtractRegion\n");
  114. #endif
  115.   OrRegionRegion((struct Region *)sra,(struct Region *)dr_return);
  116.   XorRegionRegion((struct Region*)srb,(struct Region*)dr_return);
  117.   AndRegionRegion((struct Region *)sra,(struct Region *)dr_return);
  118.   return 0;
  119. }
  120.  
  121. XDestroyRegion(r)
  122.      Region r;
  123. {
  124. #ifdef DOREGIONS
  125.   DisposeRegion((struct Region *)r);
  126. #endif /* DOREGIONS */
  127.   return;
  128. }
  129.  
  130. XClipBox(r, rect_return)
  131.      Region r;
  132.      XRectangle *rect_return;
  133. {/*                File 'xvevent.o' */
  134. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  135.   printf("WARNING:XClipBox\n");
  136. #endif
  137.   return(0);
  138. }
  139.  
  140. XUnionRectWithRegion(rectangle, src_region, dest_region_return)
  141.      XRectangle *rectangle;
  142.      Region src_region;
  143.      Region dest_region_return;
  144. {/*    File 'xvevent.o' */
  145. #ifdef DEBUGXEMUL_ENTRY
  146.   printf("XUnionRectWithRegion\n");
  147. #endif
  148. #ifdef DOREGIONS
  149.   OrRegionRegion((struct Region *)src_region,(struct Region *)dest_region_return);
  150.   OrRectRegion((struct Region *)dest_region_return,(struct Rectangle *)rectangle);
  151. #endif /* DOREGIONS */
  152.  
  153.   return(0);
  154. }
  155.  
  156. XSetRegion(display, gc, r)
  157.      Display *display;
  158.      GC gc;
  159.      Region r;
  160. {/*              File 'xvevent.o' */
  161. #ifdef DOREGIONS
  162. #ifdef DOCLIPPING
  163.   struct Region *old_region=(struct Region *)r;
  164. #endif
  165.   struct Window *win;
  166.   Window w=RootWindowOfScreen(DefaultScreenOfDisplay(display));
  167. #ifdef DEBUGXEMUL_ENTRY
  168.   printf("XSetRegion\n");
  169.   printf("XSetRegion [%d,%d][%d,%d]\n",old_region->bounds.MinX,old_region->bounds.MinY,old_region->bounds.MaxX,old_region->bounds.MaxY);
  170. #endif
  171.  
  172. #if 0
  173.   if( w==ROOTID ){
  174.     return;
  175.   }
  176.   win=X11DrawablesWindows[X11DrawablesMap[w]];
  177.   if(!win) return 0;
  178.   if(!win->WLayer){
  179.     return;
  180.   }
  181.  
  182.   if(CG.pPreviousLayer) unclipWindow(CG.pPreviousLayer);
  183.   if(win && X11ActualWindows[X11DrawablesMap[w]].mapped){
  184.     if(old_region=InstallClipRegion(win->WLayer,(struct Region *)r))
  185.       DisposeRegion(old_region);
  186.   }
  187.   CG.pPreviousLayer=win->WLayer;
  188. #endif
  189. #endif /* DOREGIONS */
  190.  
  191.   return(0);
  192. }
  193.  
  194. XIntersectRegion(sra, srb, dr_return)
  195.      Region sra, srb;
  196.      Region dr_return;
  197. {
  198. #if (DEBUGXEMUL_ENTRY)
  199.   printf("XIntersectRegion\n");
  200. #endif
  201. #ifdef DOREGIONS
  202.   OrRegionRegion((struct Region *)sra,(struct Region *)dr_return);
  203.   AndRegionRegion((struct Region *)srb,(struct Region *)dr_return);
  204. #else
  205.   return 0;
  206. #endif /* DOREGIONS */
  207. }
  208.  
  209. XUnionRegion(sra, srb, dr_return)
  210.      Region sra, srb;
  211.      Region dr_return;
  212. {
  213. #if (DEBUGXEMUL_ENTRY)
  214.   printf("XUnionRegion\n");
  215. #endif
  216. #ifdef DOREGIONS
  217.   OrRegionRegion((struct Region *)sra,(struct Region *)dr_return);
  218.   OrRegionRegion((struct Region *)srb,(struct Region *)dr_return);
  219. #else
  220.   return 0;
  221. #endif /* DOREGIONS */
  222. }
  223.  
  224. inside_rectangle( struct Rectangle rec, int x, int y ){
  225.   if( x>=rec.MinX && x<=rec.MaxX && y>=rec.MinY && y<=rec.MaxY ) return 1;
  226.   return 0;
  227. }
  228.  
  229. Bool XPointInRegion(r, x, y)
  230.      Region r;
  231.      int x, y;
  232. {
  233.   struct Region *reg=(struct Region *)r;
  234. #if (DEBUGXEMUL_ENTRY)
  235.   printf("XPointInRegion\n");
  236. #endif
  237.   if(inside_rectangle(reg->bounds,x,y))
  238.     return 1;
  239.   else {
  240.     struct RegionRectangle *rr=reg->RegionRectangle;
  241.     while( rr!=NULL ){
  242.       if( inside_rectangle(rr->bounds,x,y) ) return 1;
  243.       rr=rr->Next;
  244.     }
  245.   }
  246.   return(0);
  247. }
  248.  
  249. XXorRegion(sra, srb, dr_return)
  250.      Region sra, srb;
  251.      Region dr_return;
  252. {
  253. #if (DEBUGXEMUL_ENTRY)
  254.   printf("WARNING:XXorRegion\n");
  255. #endif
  256.   OrRegionRegion((struct Region *)sra,(struct Region *)dr_return);
  257.   XorRegionRegion((struct Region*)srb,(struct Region*)dr_return);
  258.   return(0);
  259. }
  260.